﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Emoney.UserTraining.Model;
using NHibernate.Linq;

namespace Emoney.UserTraining.DAL
{
    public class Traning_LecturerDAL
    {
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <returns></returns>
        public List<Traning_Lecturer> GetList()
        {
            using (TemporaryContext context = new TemporaryContext())
            {
                var data = context.Traning_Lecturer.Cacheable();
                return data.ToList();
            }
        }

        /// <summary>
        /// 查询数据
        /// </summary>
        /// <returns></returns>
        public Traning_Lecturer GetModel(int id)
        {
            using (TemporaryContext context = new TemporaryContext())
            {
                var data = context.Traning_Lecturer.Cacheable();
                return data.FirstOrDefault(p => p.id == id);
            }
        }

        /// <summary>
        /// 新增和修改
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public int AddUpdate(Traning_Lecturer c)
        {
            using (TemporaryContext context = new TemporaryContext())
            {
                context.Session.SaveOrUpdate(c);
                context.Session.Flush();
                return 1;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Delete(int id)
        {
            using (TemporaryContext context = new TemporaryContext())
            {
                Traning_Lecturer c = new Traning_Lecturer() { id = id };
                context.Session.Delete(c);
                context.Session.Flush();
                return 1;
            }
        }
    }
}
